﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnitLibrary.Managers;
using Microsoft.Xna.Framework;

namespace UnitLibrary.GameObjects.PowerUpEffects
{
    public class PowerUpEffect: IPowerUp
    {
        protected double _timer = 0;

        protected ComponentM _components;        

        public string Name
        { get; set; }

        public bool IsPermanent
        { get; set; }

        public double Duration
        { get; set; }

        public bool IsEnabled
        { get; set; }

        public UnitID UnitType
        { get; set; }

        public virtual void Apply()
        { IsEnabled = true; }

        public virtual void Remove()
        { }

        public virtual void Create(object existingInstance, ComponentM components)
        {
            _components = components;
            if (existingInstance != null)
            {
                PowerUpEffect powerup = (PowerUpEffect)existingInstance;
                this.Name = powerup.Name;
                this.IsPermanent = powerup.IsPermanent;
                this.Duration = powerup.Duration;
                this.IsEnabled = false;
                this.UnitType = powerup.UnitType;
            }
            this._timer = 0;
        }

        public virtual void Update(GameTime gameTime)
        {
            _timer += gameTime.ElapsedGameTime.TotalSeconds;
            if (_timer > Duration)
                IsEnabled = false;
        } 
    }
}
